package com.gmadmin.sysadmin.security.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gmadmin.gmmbg.entity.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;
import java.util.Set;

@Getter
@AllArgsConstructor
public class UserDetailsDto implements UserDetails {

    @Schema(description = "用户")
    private final SysUser user;

    @Schema(description = "角色权限")
    private final List<AuthorityDto> authorities;

    private final Set<String> roles;

    @Override
    @JsonIgnore
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    @JsonIgnore
    public String getUsername() {
        return user.getUsername();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return user.getStatus() != null && user.getStatus() == 1;
    }
}
